<?php
declare (strict_types=1);

namespace app\api\controller;

use app\api\model\Mp;
use app\api\model\User;
use app\api\model\UserTbOauth;
use app\api\model\UserTbOrder;

class Data extends Base
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function gettorder()
    {
        $page = $this->request->param('page', 1);
        $limit = $this->request->param('limit', 20);
        $count = UserTbOrder::select()->count();
        $all = UserTbOrder::order('id', 'desc')->limit(($page - 1) * $limit, (int)$limit)->select()->toArray();
        $data['code'] = 0;
        $data['msg'] = '';
        $data['count'] = $count;
        $data['data'] = $all;
        return json($data);
    }

    public function gettotalmp()
    {
        $page = $this->request->param('page', 1);
        $limit = $this->request->param('limit', 20);
        $count = Mp::select()->count();


        //$all=Mp::order('id', 'desc')->limit(   ($page-1)*$limit  ,(int)$limit  )->select()->toArray();
        $all = Mp::select()->toArray();
        $data['code'] = 0;
        $data['msg'] = '';
        $data['count'] = $count;
        $data['data'] = $all;
        return json($data);
    }


    /**
     * 显示淘宝联盟
     *
     * @return \think\Response
     */
    public function gettotbcps()
    {
        $page = $this->request->param('page', 1);
        $limit = $this->request->param('limit', 20);
        $count = UserTbOauth::where('uid', session('admin.id'))->select()->count();

        $all = UserTbOauth::where('uid', session('admin.id'))->limit(($page - 1) * $limit, (int)$limit)->select()->toArray();
        //$all=Mp::order('id', 'desc')->limit(   ($page-1)*$limit  ,(int)$limit  )->select()->toArray();

        $data['code'] = 0;
        $data['msg'] = '';
        $data['count'] = $count;
        $data['data'] = $all;
        return json($data);
    }

    /**
     * User: getRobotList
     * Notes:获取机器人的全部列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getRobotList()
    {
        $page = $this->request->param('page', 1);
        $limit = $this->request->param('limit', 20);
        $count = mp::where('uid', session('admin.id'))->select()->count();


        $all = mp::where('uid', session('admin.id'))->limit(($page - 1) * $limit, (int)$limit)->select()->toArray();

        //$all=Mp::order('id', 'desc')->limit(   ($page-1)*$limit  ,(int)$limit  )->select()->toArray();

        $data['code'] = 0;
        $data['msg'] = '';
        $data['count'] = $count;
        $data['data'] = $all;
        return json($data);
    }

    public function getUserList()
    {
        $page = $this->request->param('page', 1);
        $limit = $this->request->param('limit', 20);


        $count = User::where('uid', session('admin.id'))->select()->count();


        $all = User::where('uid', session('admin.id'))->limit(($page - 1) * $limit, (int)$limit)->select()->toArray();

        //$all=Mp::order('id', 'desc')->limit(   ($page-1)*$limit  ,(int)$limit  )->select()->toArray();

        $data['code'] = 0;
        $data['msg'] = '';
        $data['count'] = $count;
        $data['data'] = $all;
        return json($data);
    }


    public function getMemberInfo()
    {
        $id=$this->request->param('id');
        $MemberInfo=user::where('id', $id)->where('uid', session('admin.id'))->find();

        $data['code'] = 0;
        $data['data'] = $MemberInfo;


        return json($data);
    }

}
